package com.zhugang.week12;

/**
 * @program algorithms
 * @description: reverseString
 * @author: chanzhugang
 * @create: 2022/09/06 16:17
 */
public class ReverseString {

    /**
     * 344 反转字符串
     *
     * @param s
     */
    public void reverseString(char[] s) {
        // 原地修改输入数组，O(1)空间解决
        // 双指针交换
        int i = 0;
        int j = s.length - 1;
        while (i <= j) {
            char temp = s[i];
            s[i] = s[j];
            s[j] = temp;
            i++;
            j--;
        }
    }
}